package com.safe.first.application.service;

import cn.hutool.captcha.generator.RandomGenerator;
import lombok.AllArgsConstructor;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author Mickey
 * @since 2022/6/28
 **/
@Service
@AllArgsConstructor
public class SmsService {

    private final RedissonClient redissonClient;
    private final RandomGenerator randomGenerator = new RandomGenerator("0123456789", 4);

    public void code(String mobile) {
        RBucket<String> bucket = redissonClient.getBucket("sf:sms:verify_code:" + mobile);
        bucket.set(randomGenerator.generate(), 60, TimeUnit.SECONDS);
    }
}
